#######################################################
#######################################################
#######################################################
### CREATED BY JONATHAN KING AND JESSICA SCHOENHERR ###
##### REPLICATION DATA FOR "A MATTER OF OPINION?" #####
#######################################################
#######################################################
#######################################################

library(ggplot)

########################
### PREDICTED VALUES ###
########################

abortionData <- read.csv("AbortionPredictions20220225.csv")

abortionData <- as.data.frame(abortionData)

abortionData$treatmentGroup <- as.factor(abortionData$treatmentGroup)

abortionPredProb <- ggplot(abortionData, aes(y = predValue, x = treatmentGroup, ymin = lowerValue, ymax = upperValue, color = female, fill = female)) +
	geom_bar(position = position_dodge(), stat = "identity",orientation="x") +
	facet_wrap(~partisanship) + 
	geom_errorbar(position = position_dodge(0.9), width=0.2, color = "grey25") + 
	theme_bw() +
	xlab("\nOpinion Writer Treatment Groups") +
	ylab("Predicted Value - Decision Thermometer\n") +
	ggtitle("Approval for Pro-Abortion Decision") +
	theme(plot.title = element_text(hjust = 0.5)) +
	scale_x_discrete(labels = c("Liberal\nMale\nJustice", "Conservative\nMale\nJustice", "Liberal\nFemale\nJustice", "Conservative\nFemale\nJustice", "Control")) + 
	scale_y_continuous(limits = c(0, 100), breaks = seq(0, 100, 10)) +
	theme(legend.position = "bottom", legend.title = element_blank()) +
	scale_color_manual(values = c("grey75", "grey50"), labels = c("Women", "Men")) +
	scale_fill_manual(values = c("grey75", "grey50"), labels = c("Women", "Men")) +
	theme(strip.text.x = element_text(size = 12))
abortionPredProb

#######################
### BY PARTISANSHIP ###
#######################

abortionDyDx <- read.csv("AbortionDyDxPartisanship20220225.csv")

abortionDyDx <- as.data.frame(abortionDyDx)

abortionDyDx$treatmentGroup <- as.factor(abortionDyDx$treatmentGroup)

abortionChange <- ggplot(abortionDyDx, aes(y = change, x = treatmentGroup, ymin = lowerCI, ymax = upperCI)) +
	geom_hline(aes(yintercept = 0), color = "grey75", size = 1.5) +
	geom_pointrange(fatten = 1, size = 1) +
	facet_wrap(~gender) +
	theme_bw() +
	ggtitle("Differences between Democrat and Republican Participants, Approval for Pro-Abortion Decision") +
	ylab("Difference in Feeling Thermometer (Republican - Democrat)\n") +
	xlab("\nOpinion Writer Treatment Groups") +
	theme(plot.title = element_text(hjust = 0.5)) +
	scale_x_discrete(labels = c("Liberal\nMale\nJustice", "Conservative\nMale\nJustice", "Liberal\nFemale\nJustice", "Conservative\nFemale\nJustice", "Control")) +
	scale_y_continuous(limits = c(-45, 45), breaks = seq(-45, 45, 10)) +
	theme(strip.text.x = element_text(size = 12))
abortionChange

#################
### BY GENDER ###
#################

abortionDyDx2 <- read.csv("AbortionDyDxGender20220225.csv")

abortionDyDx2 <- as.data.frame(abortionDyDx2)

abortionDyDx2$treatmentGroup <- as.factor(abortionDyDx2$treatmentGroup)

abortionChange2 <- ggplot(abortionDyDx2, aes(y = change, x = treatmentGroup, ymin = lowerCI, ymax = upperCI)) +
	geom_hline(aes(yintercept = 0), color = "grey75", size = 1.5) +
	geom_pointrange(fatten = 1, size = 1) +
	facet_wrap(~partisanship) +
	theme_bw() +
	ggtitle("Differences between Male and Female Participants, Approval for Pro-Abortion Decision") +
	ylab("Difference in Feeling Thermometer (Female - Male)\n") +
	xlab("\nOpinion Writer Treatment Groups") +
	theme(plot.title = element_text(hjust = 0.5)) +
	scale_x_discrete(labels = c("Liberal\nMale\nJustice", "Conservative\nMale\nJustice", "Liberal\nFemale\nJustice", "Conservative\nFemale\nJustice", "Control")) +
	scale_y_continuous(limits = c(-45, 45), breaks = seq(-45, 45, 10)) +
	theme(strip.text.x = element_text(size = 12))
abortionChange2
